//package com.deng.leaf.core.segment.dao.impl;
//
//import com.deng.leaf.core.segment.dao.IDAllocDao;
//import com.deng.leaf.core.segment.mapper.IDAllocMapper;
//import com.deng.leaf.core.segment.model.LeafAlloc;
//import org.apache.ibatis.session.SqlSession;
//import org.apache.ibatis.session.SqlSessionFactory;
//import org.apache.ibatis.mapping.Environment;
//import org.apache.ibatis.session.Configuration;
//import org.apache.ibatis.session.SqlSessionFactoryBuilder;
//import org.apache.ibatis.transaction.TransactionFactory;
//import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory;
//import javax.sql.DataSource;
//import java.util.List;
//
//public class IDAllocDaoImpl2 implements IDAllocDao {
//
//    SqlSessionFactory sqlSessionFactory;
//
////    @Resource
//    private IDAllocMapper allocMapper;
//
//
//    public IDAllocDaoImpl2(DataSource dataSource) {
//        TransactionFactory transactionFactory = new JdbcTransactionFactory();
//        Environment environment = new Environment("development", transactionFactory, dataSource);
//        Configuration configuration = new Configuration(environment);
//        configuration.addMapper(IDAllocMapper.class);
//        sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
//    }
//
//    @Override
//    public List<LeafAlloc> getAllLeafAllocs() {
//        SqlSession sqlSession = sqlSessionFactory.openSession(false);
//        try {
//            return sqlSession.selectList("com.deng.leaf.core.segment.mapper.IDAllocMapper.getAllLeafAllocs");
//        } finally {
//            sqlSession.close();
//        }
//    }
//
//    @Override
//    public LeafAlloc updateMaxIdAndGetLeafAlloc(String tag) {
//        SqlSession sqlSession = sqlSessionFactory.openSession();
//        try {
//            sqlSession.update("com.deng.leaf.core.segment.mapper.IDAllocMapper.updateMaxId", tag);
//            LeafAlloc result = sqlSession.selectOne("com.deng.leaf.core.segment.mapper.IDAllocMapper.getLeafAlloc", tag);
//            sqlSession.commit();
//            return result;
//        } finally {
//            sqlSession.close();
//        }
//    }
//
//    @Override
//    public LeafAlloc updateMaxIdByCustomStepAndGetLeafAlloc(LeafAlloc leafAlloc) {
//        SqlSession sqlSession = sqlSessionFactory.openSession();
//        try {
//            sqlSession.update("com.deng.leaf.core.segment.mapper.IDAllocMapper.updateMaxIdByCustomStep", leafAlloc);
//            LeafAlloc result = sqlSession.selectOne("com.deng.leaf.core.segment.mapper.IDAllocMapper.getLeafAlloc", leafAlloc.getKey());
//            sqlSession.commit();
//            return result;
//        } finally {
//            sqlSession.close();
//        }
//    }
//
//    @Override
//    public LeafAlloc getLeafByTag(String tag) {
//        SqlSession sqlSession = sqlSessionFactory.openSession(false);
//        try {
//            return sqlSession.selectOne("com.deng.leaf.core.segment.mapper.IDAllocMapper.getLeafByTag",tag);
//        } finally {
//            sqlSession.close();
//        }
//    }
//
//    @Override
//    public LeafAlloc updateMaxIdEqInitValueByTag(String tag) {
//        SqlSession sqlSession = sqlSessionFactory.openSession();
//        try {
//            sqlSession.update("com.deng.leaf.core.segment.mapper.IDAllocMapper.updateMaxIdEqInitValueByTag", tag);
//            LeafAlloc result = sqlSession.selectOne("com.deng.leaf.core.segment.mapper.IDAllocMapper.getLeafByTag", tag);
//            sqlSession.commit();
//            return result;
//        } finally {
//            sqlSession.close();
//        }
//    }
//
//    @Override
//    public List<String> getAllTags() {
//        SqlSession sqlSession = sqlSessionFactory.openSession(false);
//        try {
//            return sqlSession.selectList("com.deng.leaf.core.segment.mapper.IDAllocMapper.getAllTags");
//        } finally {
//            sqlSession.close();
//        }
//    }
//}
